package com.atfcm.hash;

import java.util.HashSet;

public class T_128_最长连续序列 {
    public int longestConsecutive(int[] nums) {
        HashSet<Integer> set = new HashSet<>();
        for (int i = 0; i < nums.length; i++) {
            set.add(nums[i]);
        }
        int res = 0;

        for (Integer num : set) {
            if(set.contains(num-1)){
                continue;
            }

            int y = num + 1;
            while(set.contains(y)){
                y++;
            }
            res = Math.max(res, y-num);
        }
        return res;
    }
}
